package com.scgl.process.controller;

import java.util.Date;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.scgl.process.domain.ScglProcess;
import com.scgl.process.service.IScglProcessService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 工序任务单Controller
 *
 * @author ruoyi
 * @date 2024-10-29
 */
@RestController
@RequestMapping("/process")
public class ScglProcessController extends BaseController
{
    @Autowired
    private IScglProcessService scglProcessService;

    /**
     * 查询工序任务单列表
     */
    @RequiresPermissions("process:process:list")
    @GetMapping("/list")
    public TableDataInfo list(ScglProcess scglProcess)
    {
        startPage();
        List<ScglProcess> list = scglProcessService.selectScglProcessList(scglProcess);
        return getDataTable(list);
    }

    /**
     * 导出工序任务单列表
     */
    @RequiresPermissions("process:process:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScglProcess scglProcess)
    {
        List<ScglProcess> list = scglProcessService.selectScglProcessList(scglProcess);
        ExcelUtil<ScglProcess> util = new ExcelUtil<ScglProcess>(ScglProcess.class);
        util.exportExcel(response, list, "工序任务单数据");
    }

    /**
     * 获取工序任务单详细信息
     */
    @RequiresPermissions("process:process:query")
    @GetMapping(value = "/{processId}")
    public AjaxResult getInfo(@PathVariable("processId") String processId)
    {
        return success(scglProcessService.selectScglProcessByProcessId(processId));
    }

    /**
     * 新增工序任务单
     */
    @RequiresPermissions("process:process:add")
    @Log(title = "工序任务单新增", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScglProcess scglProcess)
    {
        scglProcess.setCreationTime(new Date());
        return toAjax(scglProcessService.insertScglProcess(scglProcess));
    }

    /**
     * 修改工序任务单
     */
    @RequiresPermissions("process:process:edit")
    @Log(title = "工序任务单修改", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScglProcess scglProcess)
    {
        return toAjax(scglProcessService.updateScglProcess(scglProcess));
    }

    /**
     * 删除工序任务单
     */
    @RequiresPermissions("process:process:remove")
    @Log(title = "工序任务单删除", businessType = BusinessType.DELETE)
	@DeleteMapping("/{processIds}")
    public AjaxResult remove(@PathVariable String[] processIds)
    {
        return toAjax(scglProcessService.deleteScglProcessByProcessIds(processIds));
    }
}
